package com.zofer.study.sort;

import java.util.Arrays;

/**
 * @description 冒泡排序
 * @date: 2020/10/9 16:48
 */
public class BubbleSort {

    public static void main(String[] args) {
        int [] arr = {2,5,6,1,3,7,9,8};
        System.out.println("排序之前:"+ Arrays.toString(arr));
        //进行排序
        dubbleSort(arr);
        System.out.println("排序之后:"+ Arrays.toString(arr));
    }

    public static void dubbleSort(int [] arr){
        for (int i = 0; i < arr.length ; i++) {
            for (int j = 0; j < arr.length - 1; j++) {
                if (arr[j] > arr[j+1]){
                    int temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = temp;
                }
            }
        }
    }
}
